import httpClient from "@/api/client.ts";
import type {Id, PageResult} from "@/api/Common.ts";
import type {
  AddRequest,
  AdminProblemVO, ExecuteCodeRequest, JudgeCase,
  ProblemVO,
  SearchByAdminParams,
  SearchParams,
  UpdateParams
} from "@/api/Problem.ts";

export const ProblemApi = {
  search: async (param: SearchParams): Promise<PageResult<ProblemVO>> => {
    const {data} = await httpClient.post<PageResult<ProblemVO>>(`/problem/search`, param)
    return data
  },

  searchByAdmin: async (param: SearchByAdminParams): Promise<PageResult<AdminProblemVO>> => {
    const {data} = await httpClient.post<PageResult<AdminProblemVO>>(`/admin/problem/search`, param)
    return data
  },

  update: async (param: UpdateParams): Promise<boolean> => {
    const {data} = await httpClient.post(`/admin/problem/update`, param)
    return data
  },

  delete: async (param: string): Promise<boolean> => {
    const {data} = await httpClient.post(`/admin/problem/delete`, null, {params: {id: param}})
    return data
  },

  add: async (param: AddRequest): Promise<boolean> => {
    const {data} = await httpClient.post(`/admin/problem/add`, param)
    return data
  },

  getCase: async (param: string): Promise<JudgeCase[]> => {
    const {data} = await httpClient.get<JudgeCase[]>(`/admin/problem/get-case`, {params: {id: param}})
    return data
  },

  doProblem: async (param: ExecuteCodeRequest): Promise<Id> => {
    const {data} = await httpClient.post(`/problem/submit`, param)
    return data
  },
  getProblem: async (param: string): Promise<ProblemVO> => {
    const {data} = await httpClient.get<ProblemVO>(`/problem/get`, {params: {id: param}})
    return data
  },

}
